//
//  LogDocument.m
//  618
//
//  Created by Ling on 13-7-9.
//
//

#import "LogDocument.h"

@implementation LogDocument
@synthesize cachefile,logContent;
static LogDocument *logDocument = nil;

+ (LogDocument*)getInstance
{
	if (logDocument == nil) {
		logDocument = [[super  alloc] init] ;
    }
    return logDocument;
}

-(id)init
{
    self = [super init];
    if (self)
    {
        NSDate *today = [NSDate date];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSString *now = [dateFormatter stringFromDate:today]; 
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSString *date = [dateFormatter stringFromDate:today];
        self.cachefile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"log/%@/%@.dat",date,now]];
        Log_Debug(@"cachefile = %@",cachefile);
        [dateFormatter release];
        
        NSString *cacheDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"log/%@",date]];
        [Util createDir:cacheDir];
        self.logContent = @"";
    }
    return self;
}
-(void)dealloc
{
    self.cachefile = nil;
    self.logContent = nil;
    [super dealloc];
}




+(void)writeLog:(NSString *)logStr
{
    return;
    NSDate *today = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *now = [dateFormatter stringFromDate:today];
    
    LogDocument *log = [self getInstance];
    log.logContent = [NSString stringWithFormat:@"%@\n%@ %@",log.logContent,now,logStr];
    NSData *contentData=[log.logContent dataUsingEncoding:NSUnicodeStringEncoding];
    [contentData writeToFile:log.cachefile atomically:NO];
    [dateFormatter release];
}



@end
